package com.jackstraw.jack_base.remote_command.service.impl;

import com.jackstraw.jack_base.remote_command.config.JschConfig;
import com.jackstraw.jack_base.remote_command.entity.Conn;
import com.jackstraw.jack_base.remote_command.entity.InstallProperties;
import com.jackstraw.jack_base.remote_command.pool.entity.SessiontConnectionConfig;
import org.springframework.stereotype.Component;

@Component("mysql" + AbstractGroupControlServiceImpl.BEAN_NAME)
public class MySQLGroupControlServiceImpl extends DockerGroupControlServiceImpl {

    public MySQLGroupControlServiceImpl(JschConfig jschConfig) {
        super(jschConfig);
    }


    @Override
    public void installSingle(InstallProperties installProperties) throws Exception {
        super.installSingle(installProperties);
        //需要暂停MYSQL，删除mysql8/data/auto.cnf,然后重启
        String cmd = "docker-compose -f docker-compose-mysql.yml ";
        cmd = "cd ".concat(DOCKER_PATH).concat(";docker-compose -f docker-compose-mysql.yml stop ; rm -rf mysql8/data/auto.cnf;docker-compose -f docker-compose-mysql.yml start");
        this.getJschService().execAllShell(Conn.buildExec(SessiontConnectionConfig.getRootConnName(installProperties.getConnName()))
                , cmd);
    }
}
